%% Fig. 3C
data = N070a;
figure(1);
clf;

h = 6.62607015e-34;
e = 1.602176634e-19;

f = data.RFFreq;
spacing = h*f / (2*e);
pcolor(data.calV' / 100 / spacing, repmat(sqrt(1e-3 * 10 .^ (data.RFAmpl'/10)), 401,1), (data.L5' / 100) / 1e-7);
shading interp;
caxis([0, 5]);
hold all;

data = N070a2;
pcolor(data.calV' / 100 / spacing, repmat(sqrt(1e-3 * 10 .^ (data.RFAmpl'/10)), 401, 1), (data.L5' / 100) / 1e-7);
shading interp;

ylim([0.01, 0.1]);
xlim([-2.5, 2.5]);

a = 1; b = 4.5;
x = [0, 2.5, b];
T = [255,179, 255; 250,250,250; 0,140,255] / 255;

caxis([0,b]);

map = interp1(x, T, linspace(0, b, 1000));
colormap(map);
colorbar();

xlabel('Voltage (hf/2e)');
ylabel('sqrt(Power) (\sqrt(mW))');

%% Fig 3C Inset: I-V
figure(5);
clf;
h = 6.62607015e-34;
e = 1.602176634e-19;

data = O070b;
f = data.RFFreq;
spacing = h*f / (2*e);
list = [53, 47, 45, 39, 33];
for i = 1:length(list)
    plot(data.calV(list(i), :) / 100 / spacing, data.K2A(list(i), :) / 151 * 1e8 +  5 + i*4);
    hold all;
    data.RFAmpl(list(i))
end

%RF off curve.
data = P070a;
offset = 15;
k = 0;
for i = 2
	plot((data.DMM2(i, :) - data.DMM2(i, 201)) / 100 / spacing, (data.K2A(i, :) / 151 * 1e8)); 
% 	plot(abs(data.DMM2(i, :) - data.DMM2(i, 201)) / 100 / spacing, abs(data.L5(i, :) / 151 * 1e8) + offset*k); 

	hold all;
	xlim([0, 2]);
	pause(1);
	k = k+1;
end



xlim([-1.5, 1.5]);
ylim([-25, 45]);
xlabel('V (hf/2e)');
ylabel('I / A (A / cm^2)');

%% Fig. 3E: plot fft vs power.
data = N070a;
idx = zeros(2, 1);
[~, idx(1)] = min(abs(data.FTFreq - 1));
[~, idx(2)] = min(abs(data.FTFreq - 2));

%idx = [351, 358, 365, 372, 379];

figure(1);
clf;

amplitude = zeros(size(data.RFAmpl, 1), 2);
for i = 1:size(data.RFAmpl)
    amplitude(i, 1) = max(abs(data.FTAmpl(i, (idx(1)-1):(idx(1)+1))));
    amplitude(i, 2) = max(abs(data.FTAmpl(i, (idx(2)-1):(idx(2)+1))));
end

for i = 1:2
    plot(amplitude(:, i).^2, sqrt(1e-3 * 10 .^ (data.RFAmpl/10)), 'linewidth', 2);
    hold all; 
    title(i);

end

legend('f = 1', 'f = 2');
ylabel('P_{RF}^{1/2} (mW^{1/2})');
xlabel('Spectral Power (arb)');
ylim([0.01,0.1]);
xlim([0, 5e-6]);

%% Fig. 3F: Shapiro at 43.7*
data = L070;

h = 6.62607015e-34;
e = 1.602176634e-19;
f = data.RFFreq
spacing = h*f/(2*e);

figure(10);
clf;

pcolor(data.calV / 100 / spacing, repmat(sqrt(1e-3 * 10 .^ (data.RFAmpl/10)), 1, size(data.calV, 2)), (data.L4 / 100) ./ (data.L5 / 10000));
hold all;
shading interp;

plot(data.calV(34, :) / 100 / spacing, 50000 * (data.K1A(34, :) / 113) + 0.05, 'color', [0,0,0]);
plot([-2.5, 2.5], sqrt(1e-3 * 10 .^ (data.RFAmpl(34)/10)) * [1,1], 'color', [1,1,1]);
plot([1.5, 1.5], 50000 * 1e-7 * [0, 1] + 0.05, 'color', [1,0,0])

% caxis(1e-5*[0.5, 2.5]);
ylim([0.01, 0.1]);
xlim([-2.5, 2.5]);

a = 0; b = 4.5;
x = [0, 2.5, b];
T = [255,179, 255; 250,250,250; 0,140,255] / 255;

caxis([0,b]);

map = interp1(x, T, linspace(0, b, 1000));
colormap(map);
colorbar();


map = interp1(x, T, linspace(0, b, 3000));
 caxis([0,b]);
colormap(map);
% pause(1);

data = L070b;
pcolor(data.calV(1:11, :) / 100 / spacing, repmat(sqrt(1e-3 * 10 .^ (data.RFAmpl(1:11)/10)), 1, size(data.calV, 2)), (data.L4(1:11, :) / 100) ./ (data.L5(1:11, :) / 10000));
shading interp;

% for k = -15:15
%    plot([-15, 12], (k)*[1,1], '-', 'color', 1*[1,1,1]);
% end
title(strcat(num2str(nanmean(nanmean(data.Temp))), 'K'));

hcb = colorbar();
title(hcb, 'dV/dI (\Omega^{-1})');
xlabel('Voltage (hf/2e)');
ylabel('sqrt(RF Power) (mW^{1/2})');

hold all;

% 70K Color plot frame
figure(11);
clf;
data = L070;

% pcolor(repmat(data.RFAmpl, 1, size(data.calV, 2)), data.calV / 100 / spacing, (data.L4 / 100) ./ (data.L5 / 10000));
% hold all;
% shading interp;

colors = jet(10);
map = interp1(x, T, linspace(0, b, 3000));

colormap(map);


plot(data.calV(34, :) / 100 / spacing, 50000 * (data.K1A(34, :) / 113) + 0.05, 'color', [0,0,0]); hold all;
plot([-2.5, 2.5], sqrt(1e-3 * 10 .^ (data.RFAmpl(34)/10)) * [1,1], 'color', [1,1,1]);
plot([1.5, 1.5], 50000 * 1e-7 * [0, 1] + 0.05, 'color', [1,0,0])

for k = -15:15
   plot([-15, 12], (k)*[1,1], '-', 'color', 1*[1,1,1]);
end
title(strcat(num2str(nanmean(nanmean(data.Temp))), 'K'));
 caxis([0,b]);
% caxis(1e-5*[0.5, 2.5]);
ylim([0.01, 0.1]);
xlim([-2.5, 2.5]);

hcb = colorbar();
title(hcb, 'dV/dI (\Omega^{-1})');
xlabel('Voltage (hf/2e)');
ylabel('RF Power (dBm)');

hold all;

% I-V Cut.
figure(11);
clf;
data = L070;
list = [21, 29, 35];
for i = 1:length(list)
    plot(data.calV(list(i), :) / 100 / spacing, data.K1A(list(i), :) / 113 * 1e8 - 25 * i, 'color', colors(i, :)); hold all;
    data.RFAmpl(list(i))
end
xlim([-1.5, 1.5]);
ylim([-230, 20]);
% yticks([-80, -40, 0, 40, 80]);
title('70 K, 47 GHz, -5.5dBm');
xlabel('V (hf/2e)');
ylabel('I / A (A/cm^2)');

plot(B002c.DMM1(7, :) / 100 / spacing - 0.3295, B002c.K1_Curr(7, :) / 113 * 1e8 - 130)

%% S14: 70K Frequency dependence of Shapiro steps. 
factor = 0.5;

figure(2);
clf;
plot(N070a2.calV(1, :) / 100 * 1000, ((N070a2.L5(1, :) - mean(N070a2.L5(1, :))) / 100 / 1e-7)  +  48.7 * factor); hold all;
plot([-0.5, 0.5], 48.7 * factor * [1,1]);

hold all;
plot(O070b.calV(31, :) / 100 * 1000, ((O070b.L5(31, :) - mean(O070b.L5(31, :))) / 100 / 1e-7)  +  41.8 * factor);
plot([-0.5, 0.5], 41.8 * factor * [1,1]);

plot(O070c.calV(48, :) / 100 * 1000, ((O070c.L5(48, :) - mean(O070c.L5(48, :))) / 100 / 1e-7)  +  34.9 * factor);
plot([-0.5, 0.5], 34.9 * factor * [1,1]);

b = 26;
for i = -3:0.5:3
    plot([0, i * (2 * b * 1e9) * h / (2*e) * 1000], [0, b], 'color', 0.75*[1,1,1]);
end

ylim([0, b]);
xlim([-0.35, 0.35]);
xlabel('Voltage (mV)');
ylabel('dV/dI + 0.5f');